﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JigLibX.Physics;
using Microsoft.Xna.Framework;
using JigLibX.Math;
using PloobsEngine.Physics.XJigLib;

namespace PloobsEngine.Behaviors
{
    public class CharacterMovimentationAction : IAction
    {

        private CharacterObject co;
        private bool isMovendoFrente = true;
        private float velo;
        private float rot=1; // em graus !!!
        private DIRECTION dir;
        private Vector3 direction;

        public enum DIRECTION { Front,Back,Left,Right,Stop,Stopping,Custom};

        public CharacterMovimentationAction(JigLibXObject obj)
        {
            co = obj as CharacterObject;
        }

        public void setVectorDirection(Vector3 vec)
        {
            this.direction = vec;
        }

        public void setDirection(DIRECTION dir)
        {

            this.dir = dir;
        }

        public void setRotation(float rot)
        {
            this.rot= rot;
        }

        public void setSpeed(float velo)
        {
            this.velo = velo;
        }

        #region IAction Members

        public string Action()
        {
            switch (dir)
            {
                case DIRECTION.Front:
                    isMovendoFrente = true;
                    co.CharacterBody.DesiredVelocity = co.FaceVector * velo;                              
                    break;
                case DIRECTION.Back:
                    isMovendoFrente = false;
                    co.CharacterBody.DesiredVelocity = -co.FaceVector * velo;                                                  
                    break;
                case DIRECTION.Left:
                    co.RotationAngle += rot;                                       
                    break;
                case DIRECTION.Right:
                    co.RotationAngle -= rot;                   
                    break;
                case DIRECTION.Stop:
                    co.CharacterBody.DesiredVelocity = Vector3.Zero;
                    break;
                case DIRECTION.Stopping:                    
                    int a = isMovendoFrente ? 1 : -1;
                    co.CharacterBody.DesiredVelocity = a * co.FaceVector * velo;                                                  
                    break;
                case DIRECTION.Custom:
                    co.CharacterBody.DesiredVelocity = direction;
                    break;
                default:
                    break;
            }

            
            return null;
        }

        #endregion
    }
}